from ..model import Model
from openai import OpenAI

class DeepSeekModel(Model):
    def __init__(self, model: str, api_key: str):
        self.model = model or "deepseek-chat"
        self.client = OpenAI(
            api_key=api_key,
            base_url="https://api.deepseek.com/v1"  # 确认API端点正确
        )

    def make_request(self, prompt):
        try:
            response = self.client.chat.completions.create(
                model=self.model,  # 此处应使用DeepSeek官方模型名称
                messages=[{"role":"user","content":prompt}],
                stream=False
            )
            return response.choices[0].message.content.strip(), True
        except Exception as e:
            # 添加详细的错误信息输出
            if hasattr(e, 'response'):
                error_data = e.response.json()
                return f"DeepSeek Error [{e.status_code}]: {error_data.get('error', {}).get('message', 'Unknown error')}", False
            return f"Error: {str(e)}", False